package org.forum.controller;

import java.io.Serializable;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.forum.domain.MainTopic;
import org.forum.service.HomeInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.Action;

/**
 * 
 * @author One
 *
 */
public class HomeInfoController {

	Logger logger = LoggerFactory.getLogger(HomeInfoController.class);

	private int pageSize = 3;

	private int pageN_news = 3;

	private int pageN_finance = 0;

	private int pageN_PE = 0;

	private int pageN_history = 0;

	private int pageN_puzzle = 0;

	private int pageN_comprehensive = 0;
	//
	private HomeInfoService homeInfoService;

	// 将要返回的json数据
	private List<MainTopic> mainTopicsAboutNews = null;

	private List<MainTopic> mainTopicsAboutFinance = null;

	private List<MainTopic> mainTopicsAboutPE = null;

	private List<MainTopic> mainTopicsAboutHistory = null;

	private List<MainTopic> mainTopicsAboutPuzzle = null;

	private List<MainTopic> mainTopicsAboutComprehensive = null;

	public HomeInfoController() {

	}

	/**
	 * @pass_Test 获取news相关信息
	 */
	public String newsInfo() {
		if (logger.isDebugEnabled()) {
			logger.debug("newsInfo method is running!");
		}
		Object oN = ServletActionContext.getRequest().getSession().getAttribute("pageN_news");
		if (oN != null) {
			pageN_news = (int) oN;
			// 临时更替
			// pageN_news = 0;
		}
		mainTopicsAboutNews = homeInfoService.getNewsInfo(pageN_news, pageSize, "addTime");
		ServletActionContext.getRequest().getSession().setAttribute("pageN_news", ++pageN_news);
		return "newsInfo";
	}

	/**
	 * @pass_Test 获取finance相关信息
	 */
	public String financeInfo() {
		if (logger.isDebugEnabled()) {
			logger.debug("financeInfo method is running!");
		}
		Object oN = ServletActionContext.getRequest().getSession().getAttribute("pageN_finance");
		if (oN != null) {
			pageN_finance = (int) oN;
			// 临时更替
			// pageN_finance = 0;
		}
		mainTopicsAboutFinance = homeInfoService.getFinanceInfo(pageN_finance, pageSize, "addTime");
		ServletActionContext.getRequest().getSession().setAttribute("pageN_finance", ++pageN_finance);
		return "financeInfo";
	}

	/**
	 * @pass_Test 获取PE相关信息
	 */
	public String PEInfo() {
		if (logger.isDebugEnabled()) {
			logger.debug("PEInfo method is running!");
		}
		Object oN = ServletActionContext.getRequest().getSession().getAttribute("pageN_PE");
		if (oN != null) {
			pageN_PE = (int) oN;
			// 临时更替
			// pageN_PE = 0;
		}

		mainTopicsAboutPE = homeInfoService.getPEInfo(pageN_PE, pageSize, "addTime");
		ServletActionContext.getRequest().getSession().setAttribute("pageN_PE", ++pageN_PE);
		return "PEInfo";
	}

	/**
	 * @pass_Test 获取history相关信息
	 */
	public String historyInfo() {
		if (logger.isDebugEnabled()) {
			logger.debug("historyInfo method is running!");
		}
		Object oN = ServletActionContext.getRequest().getSession().getAttribute("pageN_history");
		if (oN != null) {
			pageN_history = (int) oN;
			// 临时更替
			// pageN_history = 0;
		}
		mainTopicsAboutHistory = homeInfoService.getHistoryInfo(pageN_history, pageSize, "addTime");
		ServletActionContext.getRequest().getSession().setAttribute("pageN_history", ++pageN_history);
		return "historyInfo";
	}

	/**
	 * @pass_Test 获取puzzle相关信息
	 */
	public String puzzleInfo() {
		if (logger.isDebugEnabled()) {
			logger.debug("puzzleInfo method is running!");
		}
		Object oN = ServletActionContext.getRequest().getSession().getAttribute("pageN_puzzle");
		if (oN != null) {
			pageN_puzzle = (int) oN;
			// 临时更替
			// pageN_puzzle = 0;
		}
		mainTopicsAboutPuzzle = homeInfoService.getPuzzleInfo(pageN_puzzle, pageSize, "addTime");
		ServletActionContext.getRequest().getSession().setAttribute("pageN_puzzle", ++pageN_puzzle);
		return "puzzleInfo";
	}

	/**
	 * 处理：
	 * 
	 */
	public void moreForum() {

	}

	/**
	 * @pass_Test 获取comprehensive相关信息
	 */
	public String comprehensiveInfo() {
		if (logger.isDebugEnabled()) {
			logger.debug("comprehensiveInfo method is running!");
		}
		Object oN = ServletActionContext.getRequest().getSession().getAttribute("pageN_comprehensive");
		if (oN != null) {
			pageN_comprehensive = (int) oN;
			// 临时更替
			// pageN_comprehensive = 0;
		}
		mainTopicsAboutComprehensive = homeInfoService.getComprehensiveInfo(pageN_comprehensive, pageSize, "addTime");
		ServletActionContext.getRequest().getSession().setAttribute("pageN_comprehensive", ++pageN_comprehensive);
		return "comprehensiveInfo";
	}

	public void setHomeInfoService(HomeInfoService homeInfoService) {
		this.homeInfoService = homeInfoService;
	}

	// 将返回数据setter方法
	public List<MainTopic> getMainTopicsAboutNews() {
		return mainTopicsAboutNews;
	}

	public List<MainTopic> getMainTopicsAboutFinance() {
		return mainTopicsAboutFinance;
	}

	public List<MainTopic> getMainTopicsAboutPE() {
		return mainTopicsAboutPE;
	}

	public List<MainTopic> getMainTopicsAboutHistory() {
		return mainTopicsAboutHistory;
	}

	public List<MainTopic> getMainTopicsAboutPuzzle() {
		return mainTopicsAboutPuzzle;
	}

	public List<MainTopic> getMainTopicsAboutComprehensive() {
		return mainTopicsAboutComprehensive;
	}
}
